/**
=====================================================================================
 CCharplanApp
 copyright M.Jurkait 2003

 Description:
  The Application
=====================================================================================
**/
#pragma once

#ifndef __AFXWIN_H__
#error 'stdafx.h' muss vor dieser Datei in PCH eingeschlossen werden.
#endif

#include "resource.h"
#include "UpdateCheck.h"
#include <vector>


class CCharplanApp : public CWinApp
{
    private:
        struct s_report {
            enum text_type {
                TT_TEXT_EN = 0,
                TT_HTML_EN = 1,
                TT_TEXT_DE = 2,
                TT_HTML_DE = 3,
                TT_COUNT
            };

            CString name;
            CString name_de;
            CString text[TT_COUNT]; 
        };

    public:
        CCharplanApp();


    public:
        virtual BOOL InitInstance();

        afx_msg void OnAppAbout();

        afx_msg void OnLanguageDE();
        afx_msg void OnLanguageEN();
        afx_msg void OnLanguageFR();
        afx_msg void OnUpdateCommandUI_DE(CCmdUI*);
        afx_msg void OnUpdateCommandUI_EN(CCmdUI*);
        afx_msg void OnUpdateCommandUI_FR(CCmdUI*);
        afx_msg void OnDatenbankDeutsch();
        afx_msg void OnDatenbankEnglish();
        afx_msg void OnUpdateDatenbankDeutsch(CCmdUI *pCmdUI);
        afx_msg void OnUpdateDatenbankEnglish(CCmdUI *pCmdUI);
        afx_msg void OnLanguageEuroPatch();
        afx_msg void OnUpdateLanguageEuroPatch(CCmdUI *pCmdUI);
        afx_msg void OnLanguageUSPatch();
        afx_msg void OnUpdateLanguageUSPatch(CCmdUI *pCmdUI);

        afx_msg void OnDateiEinstellungen();
        afx_msg void OnFilePrintSetup();
        afx_msg void OnHilfeSendbug();
        afx_msg void OnHelpHomepage();
        virtual int ExitInstance();

#ifdef ONLY_US_DB
        void InitDB(const CString& lang);
#else
        void InitDB(const CString& lang, bool euro);
#endif

        bool TempSaveAllDocs(); 
        void TempLoadAllDocs(); 

        bool QuickLoad(const CString&);

        void OptionsLoad();
        void OptionsSave();
        void OptionsDefault(bool add = false);
        void OptionsChanged();

        void        ReportLoad();
        unsigned    ReportName(unsigned idx, mstring&);
        CString     ReportGet(unsigned idx, bool puretxt);

        void    OpenURL(const char*url);
        CString GetDataPath();

        bool    GetProgramVersion(DWORD &hi, DWORD &lo);


    private:
        void RunUpdateCheck();
        void CheckEgg();
        afx_msg void OnHilfeUpdatepr32796();

        void ReportLoad(mstring);

    public:
        CValueTable  ma_options;
        CValueTableStr ma_options_str;

    private:
        CString  mstr_prg_path;
        CString  mstr_user_data_path;

        std::vector<s_report> m_reports;

        CUpdateCheck mc_update;


    DECLARE_MESSAGE_MAP()
};

extern CCharplanApp theApp;

// helper
bool  AddMenuItem(HMENU hTargetMenu,  const CString& itemText, UINT itemID);
bool  AddMenuItem(HMENU hTargetMenu, const CString& itemText, UINT itemID, int position);


#define GETOPTION(x)   (((CCharplanApp*)AfxGetApp())->ma_options.GetValue(x))
#define GETOPTIONDEF(x,y)  (((CCharplanApp*)AfxGetApp())->ma_options.GetValue(x,y))
#define SETOPTION(x,y)   (((CCharplanApp*)AfxGetApp())->ma_options.SetValueAndAdd(x,y))
#define GETOPTION_STR(x)  (((CCharplanApp*)AfxGetApp())->ma_options_str.GetValue(x))
#define GETOPTIONDEF_STR(x,y) (((CCharplanApp*)AfxGetApp())->ma_options_str.GetValue(x,y))
#define SETOPTION_STR(x,y)  (((CCharplanApp*)AfxGetApp())->ma_options_str.SetValueAndAdd(x,y))
